package com.emax.zhenghe.rpcapi.modules.bill.vo;

import com.emax.channel.rpcapi.levyInvoice.dto.LevyInvoiceInfoFileDTO;
import com.emax.plat.BusinessTypeEnum;
import com.emax.zhenghe.common.enums.PlatformPartnerEnum;
import com.emax.zhenghe.common.enums.ProductEnum;
import com.emax.zhenghe.common.enums.invoice.*;
import com.emax.zhenghe.rpcapi.modules.base.SelectId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Description: 开票管理
 * @Author: jeecg-boot
 * @Date:   2020-05-08
 * @Version: V1.0
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="emax_bill对象", description="开票管理")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class EnterpriseInvoiceApplyVO implements Serializable{

	private static final long serialVersionUID = 7868645821348565096L;
	/**billNo*/
	@Excel(name = "发票申请号", width = 15)
    @ApiModelProperty(value = "billNo")
	@JsonSerialize(using= ToStringSerializer.class)
	@SelectId
	private Long billNo;
	/**结算编号*/
    @ApiModelProperty(value = "结算编号")
	@JsonSerialize(using= ToStringSerializer.class)
	private Long settlementNo;

	@Excel(name = "客户名称", width = 20)
	private String enterpriseName;

	private String enterpriseCompanyName;

	/**申请日期*/
	@Excel(name = "申请日期", width = 20, format = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "申请日期")
	private Date applyTime;
	/**开票人手机号*/
	//@Excel(name = "开票人手机号", width = 15)
	@ApiModelProperty(value = "applyPhone")
	private String applyPhone;
	/**开票金额*/
	@Excel(name = "开票金额", width = 15)
    @ApiModelProperty(value = "开票金额")
	@NotNull(message = "开票金额不能为空")
	private BigDecimal billAmount;
	@Excel(name = "税额", width = 15)
	@ApiModelProperty(value = "税额")
	private BigDecimal billTaxAmount;
	@Excel(name = "金额（不含税）", width = 15)
	@ApiModelProperty(value = "金额（不含税）")
	private BigDecimal billNotTaxAmount;
	@Excel(name = "是否邮寄", width = 15,exportConvert = true)
	@ApiModelProperty(value = "是否邮寄 0未邮寄 1已邮寄")
	@JsonSerialize(using= ToStringSerializer.class)
	private Integer expressIsDelivered;

	/**enterpriseId*/
	@Excel(name = "客户ID", width = 15)
    @ApiModelProperty(value = "enterpriseId")
	@JsonSerialize(using= ToStringSerializer.class)
	@NotNull(message = "客户编号不能为空")
	private Long enterpriseId;

	/**enterpriseId*/
	@ApiModelProperty(value = "enterpriseId")
	@JsonSerialize(using= ToStringSerializer.class)
	private List<String> enterpriseIds;

	/**enterpriseName*/
	@Excel(name = "营业执照名称", width = 15)
    @ApiModelProperty(value = "licenseEnterpriseName")
	private String licenseEnterpriseName;


	/**纳税人识别号*/
	@Excel(name = "纳税人识别号", width = 15)
	@ApiModelProperty(value = "纳税人识别号")
	private String taxpayerNo;
	/**开户银行*/
	@ApiModelProperty(value = "开户银行")
	@Excel(name = "开户银行", width = 20)
	private String bankName;
	/**开户账号*/
	@ApiModelProperty(value = "开户账号")
	@Excel(name = "开户账号", width = 25)
	private String bankCardNo;
	/**开票地址*/
	@Excel(name = "开票地址", width = 25)
	@ApiModelProperty(value = "开票地址")
	private String billAddress;
	/**开票电话*/
	@Excel(name = "开票电话", width = 15)
	@ApiModelProperty(value = "开票电话")
	private String billPhone;
	/**开票备注*/
	@Excel(name = "开票备注", width = 15)
	@ApiModelProperty(value = "开票备注")
	private String billRemark;

	/**
	 * 开票方类型，InvoiceMakerTypeEnum
	 */
	@ApiModelProperty(value = "invoiceMakerType")
	@JsonSerialize(using= ToStringSerializer.class)
	@NotNull(message = "开票方类型不能为空")
	private PlatformPartnerEnum invoiceMakerType;
	/**开票方id*/
	//@Excel(name = "开票方id", width = 15)
	@NotNull(message = "开票方编号不能为空")
	private Long invoiceMakerId;
	/**开票方名称*/
	@Excel(name = "开票方名称", width = 64)
	@ApiModelProperty(value = "invoiceMakerName")
	@NotNull(message = "开票方名称不能为空")
	private String invoiceMakerName;

	/**发票类型BillTypeEnum的code:SPECIAL-专票,PLAIN-普票*/
	@Excel(name = "发票类型", width = 15, exportConvert = true)
	@ApiModelProperty(value = "invoiceType")
	@NotNull(message = "发票类型不能为空")
	private String invoiceType;

	/**
	 * 开票类目id.
	 * 值是{@link com.emax.channel.rpcapi.levyinvoiceclass.vo.LevyInvoiceClassVO#id}, 不是{@link com.emax.channel.rpcapi.levyinvoiceclass.vo.LevyInvoiceClassVO#levyBillClassId}
	 */
	//@Excel(name = "开票类目id", width = 15)
	@ApiModelProperty(value = "开票类目id")
	@NotNull(message = "开票类目不能为空")
	private Long billCategoryId;

	@ApiModelProperty(value = "发票类目类别")
	private BillCategoryTypeEnum billCategoryType;

	/**开票类目*/
	@Excel(name = "开票类目", width = 15)
    @ApiModelProperty(value = "开票类目")
	@NotNull(message = "开票类目不能为空")
	private String billCategoryName;

	/**billStatus*/
	@Excel(name = "开票状态", width = 15, exportConvert = true)
    @ApiModelProperty(value = "billStatus")
	private String billStatus;
	/**发票代码*/
	@Excel(name = "发票代码", width = 15)
    @ApiModelProperty(value = "发票代码")
	private String billCode;
	/**发票号码*/
	@Excel(name = "发票号码", width = 15)
    @ApiModelProperty(value = "发票号码")
	private String billNumber;
	/**createTime*/
	//@Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "createTime")
	private Date createTime;
	/**mailingAddress*/
    @ApiModelProperty(value = "mailingAddress")
	@Excel(name = "邮寄地址", width = 20)
	private String mailingAddress;

	/**收件人*/
    @ApiModelProperty(value = "收件人")
	@Excel(name = "收件人", width = 15)
	private String mailingReceiver;

	/**邮寄收件人手机号*/
    @ApiModelProperty(value = "邮寄收件人手机号")
	@Excel(name = "邮寄收件人", width = 15)
	private String mailingReceiverPhone;

	/**接收行程单和发票的邮箱*/
	@ApiModelProperty(value = "接收行程单和发票的邮箱")
	private String email;

	/**开票时间*/
	@Excel(name = "开票时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "开票时间")
	private Date billSuccessTime;

	/**业务类型 boss开工：BOSSKG，会出行：HUICHUXING*/
	@Excel(name = "业务类型", width = 15, exportConvert = true)
    @ApiModelProperty(value = "业务类型")
	@NotNull(message = "业务类型不能为空")
	private String product;

	/**渠道请求类型 PC、H5*/
	@Excel(name = "渠道请求类型 PC、H5", width = 15)
	@ApiModelProperty(value = "渠道请求类型 PC、H5")
	private String channelType;

	/**结算单名称*/
	@Excel(name = "结算单名称", width = 15)
	@ApiModelProperty(value = "结算单名称")
	private String settlementName;
	/**
	 * 快递公司
	 */
	@Excel(name = "快递公司", width = 64)
	@ApiModelProperty(value = "快递公司")
	private String expressCompany;
	/**
	 * 快递单号
	 */
	@Excel(name = "快递单号", width = 32)
	@ApiModelProperty(value = "快递单号")
	private String expressDeliveryNo;

	@ApiModelProperty(value = "票据类型 TicketTypeEnum PAPER(纸票) ELECTRONIC(电票)")
	private String ticketType;

	@Excel(name = "票据类型", width = 15)
	@ApiModelProperty(value = "票据类型 TicketTypeEnum PAPER(纸票) ELECTRONIC(电票)")
	private String ticketTypeName;

	/**
	 * 订单号，逗号分隔开，做校验
	 */
	private String orderNos;

	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private String applyTimeBegin;
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private String applyTimeEnd;

	//电子发票下载地址
	private String billUrl;
	//父billNo
	@ApiModelProperty(value = "parentBillNo")
	@JsonSerialize(using= ToStringSerializer.class)
	private Long parentBillNo;
	//子billNo
	@Excel(name = "重开申请号", width = 20)
	@ApiModelProperty(value = "sonBillNo")
	@JsonSerialize(using= ToStringSerializer.class)
	private Long sonBillNo;


	@ApiModelProperty(value = "作废原因 1销货退回 2开票有误 3服务中止 4销售折让")
	private Integer redReasonType;


	@ApiModelProperty(value = "作废按钮展示 作废0 红冲1")
	private Integer invoiceCancelType;

	@ApiModelProperty(value = "礼品服务商idList")
	private List<Long> giftLevyIdList;

	//是否重新开票成功
	private boolean retBilled;

	//行程单地址
	private String tripUrl;
	//审核备注
	private String auditRemark;

	//发票图片
	private String billImage;

	// 开票时间开始
	private String billSuccessTimeBegin;

	// 开票时间结束
	private String billSuccessTimeEnd;

	// 来源名称
	private String productName;


	// 来源名称
	private List<String> productList;

	//操作人
	private String operatorName;


	//发票记录id
	@ApiModelProperty(value = "发票记录id 详情修改快递信息时有值")
	private String recordNo;

	// 发票状态名称
	private List<String> billStatusList;

	/**
	 * 客户属性：ENT企业客户;PERSON个人客户
	 */
	@NotNull(message = "客户属性不能为空")
	private String clientType;

	// 是否可以发送邮件 0不能 1可以
	private Integer sendEmailStatus;

	/**
	 * 产品线细分业务类型 {@link BusinessTypeEnum}
	 */
	private String businessType;

	/**
	 * 业务线申请开票流水号
	 */
	private String businessFlowNo;


	@Excel(name = "服务商流水号", width = 64)
	private String thirdFlowNo;

	/**归档状态*/
	@Excel(name = "归档状态", width = 64)//@see EnterpriseAgreementVo 归档状态0.未归档1.已归档
	private String archived;

    /**
     * 商户编码列表，当前仅用在发票查询
     */
    private List<Long> enterpriseIdList;


	/**
	 * 查询条件增加开票方类型数组
	 */
	private List<PlatformPartnerEnum> invoiceMakerTypeList;
	/**
	 * 发票价税类型，
	 * {@link InvoiceTaxTypeEnum}
	 */
	private InvoiceTaxTypeEnum invoiceTaxType;

	/**
	 * 开票格式
	 * {@link InvoiceFormatTypeEnum}
	 */
	@Excel(name = "开票格式", width = 15)
	private InvoiceFormatTypeEnum invoiceFormatType;


	/**
	 * 开票形式 线上/线下
	 */
	private InvoiceWayEnum invoiceWay;

	/**
	 * 服务商文件
	 */
	private List<LevyInvoiceInfoFileDTO> levyFileList;

	public String convertisBillStatus(){
		if(StringUtils.isNotBlank(this.getBillStatus())) {
			return InvoiceApplyStatusEnum.getBeanByValue(this.getBillStatus()).getValue();
		}else{
			return "";
		}
	}

	public String convertisProduct(){
		if(StringUtils.isNotBlank(this.getProduct())) {
			return ProductEnum.getContentByValue(this.getProduct());
		}else{
			return "";
		}
	}

	public String convertisInvoiceType(){
		if(StringUtils.isNotBlank(this.getInvoiceType())) {
			BillTypeEnum beanByCode = BillTypeEnum.getBean(this.getInvoiceType());
			return beanByCode.getValue();
		}
		return "";
	}

	public String convertisExpressIsDelivered(){
		Integer expressIsDelivered = this.getExpressIsDelivered();
		if(expressIsDelivered != null) {
			return ExpressIsDeliveredEnum.getValueByCode(expressIsDelivered);
		}
		return "";
	}
}
